#ifndef CXTYPE_HPP
#define CXTYPE_HPP

#include <dc1394/dc1394.h>
#include <unistd.h>
#include <string>

using std::string;

typedef     unsigned long long      guid;
typedef     unsigned int            uint;
typedef     unsigned char           uchar;
typedef     unsigned int            _CxResult;

#ifndef NDEBUG
    #include <assert.h>
    #include <iostream>
    #define		DEBUG_PRINT			std::cout
    #define		PRINT_END			std::endl

/*  WIN32   */
    #ifdef WIN32
        #define		CX_ASSERT(expr)	assert(expr)
        #ifdef _UNICODE
            #define		CX_ASSERT_MSG(expr,msg)		\
                            _wassert( _CRT_WIDE(    ##msg	L"\n"), _CRT_WIDE(__FILE__), __LINE__)
        #else
            #define		CX_ASSERT_MSG(expr,msg)		\
                            _wassert( ##msg	"\n", __FILE__, __LINE__)
        #endif
/*  UNIX  */
    #else

        #define		CX_ASSERT(expr)	assert(expr)
        #define		CX_ASSERT_MSG(expr,msg)		__assert(	msg  , __FILE__, __LINE__)

#endif

#else
        #define		CX_ASSERT(expr)
        #define		CX_ASSERT_MSG(expr,msg)
        #define		DEBUG_PRINT
        #define		PRINT_END
#endif

const char dc1394errmsg[][64]=
{
    "DC1394_FAILURE                     = -1",
    "DC1394_NOT_A_CAMERA                = -2",
    "DC1394_FUNCTION_NOT_SUPPORTED      = -3",
    "DC1394_CAMERA_NOT_INITIALIZED      = -4",
    "DC1394_MEMORY_ALLOCATION_FAILURE   = -5",
    "DC1394_TAGGED_REGISTER_NOT_FOUND   = -6",
    "DC1394_NO_ISO_CHANNEL              = -7",
    "DC1394_NO_BANDWIDTH                = -8",
    "DC1394_IOCTL_FAILURE               = -9",
    "DC1394_CAPTURE_IS_NOT_SET          = -10",
    "DC1394_CAPTURE_IS_RUNNING          = -11",
    "DC1394_RAW1394_FAILURE             = -12",
    "DC1394_FORMAT7_ERROR_FLAG_1        = -13",
    "DC1394_FORMAT7_ERROR_FLAG_2        = -14",
    "DC1394_INVALID_ARGUMENT_VALUE      = -15",
    "DC1394_REQ_VALUE_OUTSIDE_RANGE     = -16",
    "DC1394_INVALID_FEATURE             = -17",
    "DC1394_INVALID_VIDEO_FORMAT        = -18",
    "DC1394_INVALID_VIDEO_MODE          = -19",
    "DC1394_INVALID_FRAMERATE           = -20",
    "DC1394_INVALID_TRIGGER_MODE        = -21",
    "DC1394_INVALID_TRIGGER_SOURCE      = -22",
    "DC1394_INVALID_ISO_SPEED           = -23",
    "DC1394_INVALID_IIDC_VERSION        = -24",
    "DC1394_INVALID_COLOR_CODING        = -25",
    "DC1394_INVALID_COLOR_FILTER        = -26",
    "DC1394_INVALID_CAPTURE_POLICY      = -27",
    "DC1394_INVALID_ERROR_CODE          = -28",
    "DC1394_INVALID_BAYER_METHOD        = -29",
    "DC1394_INVALID_VIDEO1394_DEVICE    = -30",
    "DC1394_INVALID_OPERATION_MODE      = -31",
    "DC1394_INVALID_TRIGGER_POLARITY    = -32",
    "DC1394_INVALID_FEATURE_MODE        = -33",
    "DC1394_INVALID_LOG_TYPE            = -34",
    "DC1394_INVALID_BYTE_ORDER          = -35",
    "DC1394_INVALID_STEREO_METHOD       = -36",
    "DC1394_BASLER_NO_MORE_SFF_CHUNKS   = -37",
    "DC1394_BASLER_CORRUPTED_SFF_CHUNK  = -38",
    "DC1394_BASLER_UNKNOWN_SFF_CHUNK    = -39"
};



const char modestr[][128]={
    "DC1394_VIDEO_MODE_160x120_YUV444",
    "DC1394_VIDEO_MODE_320x240_YUV422",
    "DC1394_VIDEO_MODE_640x480_YUV411",
    "DC1394_VIDEO_MODE_640x480_YUV422",
    "DC1394_VIDEO_MODE_640x480_RGB8",
    "DC1394_VIDEO_MODE_640x480_MONO8",
    "DC1394_VIDEO_MODE_640x480_MONO16",
    "DC1394_VIDEO_MODE_800x600_YUV422",
    "DC1394_VIDEO_MODE_800x600_RGB8",
    "DC1394_VIDEO_MODE_800x600_MONO8",
    "DC1394_VIDEO_MODE_1024x768_YUV422",
    "DC1394_VIDEO_MODE_1024x768_RGB8",
    "DC1394_VIDEO_MODE_1024x768_MONO8",
    "DC1394_VIDEO_MODE_800x600_MONO16",
    "DC1394_VIDEO_MODE_1024x768_MONO16",
    "DC1394_VIDEO_MODE_1280x960_YUV422",
    "DC1394_VIDEO_MODE_1280x960_RGB8",
    "DC1394_VIDEO_MODE_1280x960_MONO8",
    "DC1394_VIDEO_MODE_1600x1200_YUV422",
    "DC1394_VIDEO_MODE_1600x1200_RGB8",
    "DC1394_VIDEO_MODE_1600x1200_MONO8",
    "DC1394_VIDEO_MODE_1280x960_MONO16",
    "DC1394_VIDEO_MODE_1600x1200_MONO16",
    "DC1394_VIDEO_MODE_EXIF",
    "DC1394_VIDEO_MODE_FORMAT7_0",
    "DC1394_VIDEO_MODE_FORMAT7_1",
    "DC1394_VIDEO_MODE_FORMAT7_2",
    "DC1394_VIDEO_MODE_FORMAT7_3",
    "DC1394_VIDEO_MODE_FORMAT7_4",
    "DC1394_VIDEO_MODE_FORMAT7_5",
    "DC1394_VIDEO_MODE_FORMAT7_6",
    "DC1394_VIDEO_MODE_FORMAT7_7"
};


const char ratestr[][128]=
{
    "DC1394_FRAMERATE_1_875",
    "DC1394_FRAMERATE_3_75",
    "DC1394_FRAMERATE_7_5",
    "DC1394_FRAMERATE_15",
    "DC1394_FRAMERATE_30",
    "DC1394_FRAMERATE_60",
    "DC1394_FRAMERATE_120",
    "DC1394_FRAMERATE_240"
};



inline    const  char   *formatRates(dc1394framerate_t rate)
{
    return ratestr[rate-32];
}
inline   const   char    *formatModes(dc1394video_mode_t mode)
{
    return modestr[mode-64];
}
inline      void    _printError(dc1394error_t error)
{
    if(error==DC1394_SUCCESS)
        return ;
    int index=-((int )error)-1;
    fprintf(stderr,"DC1394 ERROR: %s\nExit Program...\n",dc1394errmsg[index]);
    _exit(-1);
}

#define			printError(error) 	\
                if(error!=DC1394_SUCCESS)	\
                    fprintf(stderr,"File: %s \nLine: %d\n",__FILE__,__LINE__); \
                _printError(error)


#endif // CXTYPE_HPP
